<?php

namespace frontend\models;

use common\helpers\Url;

/**
 * MemberSearch is the search model class for member.
 *
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class MemberSearch extends \common\models\member\Member {

    /**
     * {@inheritdoc}
     */
    public static function findByUserId($id) {
        $query = static::find()->active();
        $query->andWhere(['user_id' => $id]);
        return $query->one();
    }

    /**
     * {@inheritdoc}
     */
    public function getTips() {
        if ($this->audit_status == static::AUDIT_STATUS_FORBID) {
            return [
                'title' => '抱歉，您的会员申请未通过',
                'text' => '',
                'icon' => '',
                'link' => Url::weblink('member.payment'),
            ];
        } elseif ($this->audit_status == static::AUDIT_STATUS_REJECT) {
            return [
                'title' => '抱歉，您的会员申请未通过',
                'text' => '补充资料',
                'icon' => '',
                'link' => Url::weblink('member.payment'),
            ];
        } elseif ($this->audit_status == static::AUDIT_STATUS_ALLOW) {
            return [
                'title' => '恭喜您，您的会员申请审核通过',
                'text' => '',
                'icon' => '',
                'link' => Url::weblink('member.payment'),
            ];
        } elseif ($this->audit_status == static::AUDIT_STATUS_FINISH) {
            return [
                'title' => '尊敬的优越定制会员，您可以进入会员中心',
                'text' => '',
                'icon' => '',
                'link' => Url::weblink('member.payment'),
            ];
        } elseif ($this->audit_status == static::AUDIT_STATUS_DEFAULT) {
            return [
                'title' => '会员申请资料已填写还未提交',
                'text' => '提交审核',
                'icon' => '',
                'link' => Url::weblink('member.payment'),
            ];
        } elseif ($this->audit_status == static::AUDIT_STATUS_SUBMIT) {
            return [
                'title' => '会员申请资料已提交',
                'text' => '等待审核',
                'icon' => '',
                'link' => Url::weblink('member.payment'),
            ];
        } elseif ($this->audit_status == static::AUDIT_STATUS_ACCEPT) {
            return [
                'title' => '您的会员申请已被受理',
                'text' => '审核中',
                'icon' => '',
                'link' => Url::weblink('member.payment'),
            ];
        }
        return null;
    }

    /**
     * {@inheritdoc}
     */
    public function getOperation() {
        if ($this->audit_status == static::AUDIT_STATUS_DEFAULT || $this->audit_status == static::AUDIT_STATUS_SUBMIT) {
            return [
                'action' => 'view',
                'text' => '查看资料',
                'link' => Url::weblink('member/data'),
            ];
        } elseif ($this->audit_status == static::AUDIT_STATUS_REJECT) {
            return [
                'action' => 'view',
                'text' => '补充资料',
                'link' => Url::weblink('member/data'),
            ];
        } elseif ($this->audit_status == static::AUDIT_STATUS_ALLOW) {
            return [
                'action' => 'payment',
                'text' => '立即缴费',
                'link' => null,
            ];
        }
        return null;
    }

    /**
     * {@inheritdoc}
     */
    public function getFullData() {
        $return = [
            'memberId' => $this->id,
            'typeId' => $this->type_id,
        ];
        if ($this->data) {
            $data = $this->data->getCamelAttributes([
                'realname',
                'idcardno',
                'mobile',
                'photo',
                'passport_front',
                'passport_reverse',
            ]);
        }
        if ($this->personal) {
            $personal = $this->personal->getCamelAttributes([
                'province',
                'city',
                'district',
                'area_code',
                'address_detail',
                'postal_code',
                'organization',
                'qualification',
                'occupation',
                'income',
            ]);
        }
        return array_merge($return, $data, $personal);
    }

}
